home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 21
/
AMIGAplus Sonderheft 21 (1999)(ICP)(DE)[!].iso
/
PublicDomain
/
System
/
httplister
/
arexx
/
HTTPlister.rexx
Wrap
OS/2 REXX Batch file
|
1999-08-23
|
22KB
|
938 lines
/* $VER: HTTPlister.rexx 1.9 1999
Copyright © 1998 Brian Scott
Email: bscott@odyssey.apana.org.au
*/
/* *** HTTPResume by Andrija Antonijevics IS REQUIRED. ***
This ARexx script reads and lists an aminet listing either the RECENT
file or another of the same format into a Dopus lister.
You get 3 columns, Name, Comment & Date giving you the instant sorting
that Dopus provides in any column by selecting either the 'Name',
'Comment' or 'Date' column labels in the lister.
The aminet file's Dir, Size & Desc. go in the 'Comment' column.
Selecting the 'Comment' label in the lister gets all the aminet
directories sorted into groups.
Selecting the 'Date' label in the lister gets all the lines sorted in
the same order as they were in the file they came from. (The 'dates'
are meaningless - generated for sorting purposes only).
It is actually the 'time' part of the date field that gets incremented,
the dates remain constant.
o The most downloaded files from Aminet during the week have the date
22-Feb-88.
o The highest rated programs during the week have the date 30-Mar-98.
o The rest have the date 01-Jan-78.
By adding aminet direc/tories to the FilterOut string below,
you can prevent some from being listed in the lister.
Check it out as I've left a couple there as examples and you may
want to list them.
When you run this script from a Dopus menu etc. set the flag
Run asynchronously.
YOU WILL NEED TO CHANGE THE VALUE OF THESE VARIABLES:
----------------------------------------------------
o HTTPresume (HTTPresume with it's full path)
o PRXY (Your proxy:port) /* See the HTTPResume docs on setting PROXY */
o amiURL Your aminet URL (Should start with http://)
o and as mentioned the FilterOut string will need editing.
If you wish to use this without a proxy remove the PRXY variable line and
make sure that the aminet URL (amiURL variable below) you choose starts
with 'http://' and not 'ftp://'. (This comes from someone that doesn't
use a proxy. I use one so I can't test this).
And if you like you can free up the sound system below. For indicating
when the downloading has finished.
Note!
* This is strictly USE AT YOUR OWN RISK.
* This has only been tested with Directory Opus 5.661 Magellan and
* HTTPResume 1.3.
* The names listed in the lister are only pseudo-files and can't be
* treated as you would other file names in normal listers. Only apply
* the actions that I outline and it should all work OK.
*/
/***** Main Variables *********/
/* As many as you like, that you DON'T want in the lister. */
FilterOut = "comm/ambos comm/bbs comm/cnet" /* eg. */
HTTPresume = 'DATA:COMM/WEB/HTTPResume/HTTPResume'
PRXY = "HTTP://anonymous:you@where.ever.you.are:8080"
/* Suit yourself for your aminet URL */
amiURL.0 = 3 /* Set this to how many amiURLs do you have. */
/* amiURL.1 is always the default when HTTPlister.rexx starts up. */
amiURL.1 = "http://ftp.uni-paderborn.de/pub/aminet/" /* Germany ALL */
amiURL.2 = "http://sunsite.doc.ic.ac.uk/packages/amiga/" /* UK ? */
amiURL.3 = "http://ftp.wustl.edu/pub/aminet/" /* USA (MO) ALL */
DDir = "RAM:" /* Where the downloaded files will end up. */
/***** Start of Sound System setup *********/
/* You'll need to free this up (remove the comment tags)
and give paths etc. for your player and sound file.
*/
/* For the system to work REMOVE THIS LINE..
soundafter = 300 /* Only play a sound (to notify finish of downloading) */
/* if it takes longer than this many seconds to download. */
/* Find sound files at http://www.moviesounds.com/ */
fini_sound = "DATA:COMM/Sound/12-1234.wav"
soundplayer = "c:play16"
/* eg. of how it's run.. ADDRESS command soundplayer||" >nil: "||fini_sound */
*/ ..and REMOVE THIS LINE too for the sound system to work
/***** End of Sound System setup *********/
/****** **********/
/***** It's All Action from here on.. (Tamper at your own peril.) *********/
/****** **********/
parse arg listingfyl
ADDRESS 'DOPUS.1'
OPTIONS RESULTS
OPTIONS failat 40
signal on syntax
LF = '0a'x
dopus version
If ( result='RESULT' | translate(result,'.',' ') < 5.1218 ) then do
dopus request '"This script requires DOpus v5.5 or greater." OK'
EXIT
end
httpargs = sethttparg(DDir)
oldsel = 0
tick = 1
amiURL = amiURL.tick
maxsgsz = 3000 /* Msg of day size to show in Req. Larger gets Read. */
HTTPlabel = "HTTPlister"
topdefault = "Aminet listing"
toploading = 'Loading list..'
prefile = "sys:s/httppreselected"
Amotd = ""
HTTPToolBar = "GETAMINET.BUTTONS"
if ~show('L','rexxsupport.library') then
addlib('rexxsupport.library',0,-30,0)
if listingfyl = "" then listingfyl = slcd()
if listingfyl ~= "" then do
listingOK = chkfyl(listingfyl) /* Returns with the listing file still open. */
if ~listingOK then do
CALL close('r')
CALL tata(listingfyl||LF||'"Doesn''t contain an aminet listing."')
end
ln = chkln /* The first line that proved to be of aminet format. */
running = chkrunning() /* Check if HTTPlister is already running, if it is */
/* use the same lister to view an incoming list. */
if running > 0 then do
CALL loadrunning(running)
if Amotd ~= "" then CALL readAmotd() /* Message of the day. */
CALL chkpresel() /* Check for preselected file names. */
EXIT
end
end
lister new "1/11/690/425 "
ALH = result
lister set ALH TOOLBAR HTTPToolBar /* getaminet.buttons */
lister set ALH display name comment date
lister set ALH source
lister set ALH title toploading
lister set ALH label HTTPlabel
lister clear ALH
lister refresh ALH full
if listingfyl ~= "" then do
lister set ALH busy 1
CALL loadlist() /* Listing file gets closed here. */
topmsg = gettopmsg(listingfyl)
lister set ALH busy 0
end
else topmsg = "Waiting for RECENT file:"
lister set ALH title topmsg
lister refresh ALH full
handlername = "_HTTPlister"
dopus addtrap '*' handlername /* Trap all dopus commands. */
dopus remtrap 'none' handlername /* UnSelect button uses 'none' */
if Amotd ~= "" then CALL readAmotd()
CALL chkpresel() /* Check for preselected file names. */
lister set ALH handler handlername
CALL openport(handlername)
do until event='inactive'
if waitpkt(handlername) then do
packet=getpkt(handlername)
if packet~='00000000'x then do
event=getarg(packet,0)
desti=getarg(packet,1)
namestr=getarg(packet,2)
user=getarg(packet,3)
pathstr=getarg(packet,4)
reqreturn=getarg(packet,5)
qualifier=getarg(packet,6)
CALL delay(10)
select
when (qualifier='shift') & (event='doubleclick') then
CALL readOPT()
when event='dereselect' then /* De-Reselect */
oldsel = dereselect(oldsel)
when event='preselect' then /* Preselect */
CALL preselect()
when event='dlselected' then
CALL downloadOPT()
when event='chgurl' then do
amiURL = chngURL()
CALL timedmsg(amiURL, 75)
end
when event='showurl' then /* Show current URL */
CALL timedmsg(amiURL, 80)
when event='search' then do
lister set ALH source
lister set ALH busy 1
CALL findstring()
lister set ALH busy 0
end
when (event='doubleclick') then CALL timedmsg("'Shift-Select' for .readme", 150)
when (event='dlrecent') then do
gotrcnt = downloadrcnt()
if ~gotrcnt then
CALL givemsg('"RECENT failed to download!"')
else do
CALL load("RAM:RECENT")
if Amotd ~= "" then CALL readAmotd()
end
end
when (event='drop') then do
if words(namestr) = 1 then do
lister query user path
reqreturn = result||namestr
Amotd = ""
CALL load(reqreturn)
if Amotd ~= "" then CALL readAmotd()
CALL chkpresel() /* Check for preselected file names. */
end
else CALL givemsg('"You need to provide ONE aminet listing file."')
end
when (qualifier='shift') & (event='dropfrom') then do
lister query user busy
if ~result then do
if words(namestr) = 1 then do
DDir = reqreturn
Dhandle = user /* Adopt lister for downloading */
CALL readOPT()
end
else
CALL givemsg('"Sorry only ONE readme at a time."')
end
end
when (event='dropfrom') then do
lister query user busy
if ~result then do
DDir = reqreturn
Dhandle = user
lister set user dest
lister refresh user
do s = 1 to words(namestr) /* 'dropfrom' de-selected them. */
lister select ALH word(namestr,s) on
end
lister refresh ALH
CALL downloadOPT()
end
end
otherwise NOP
end
CALL reply(packet,0)
end
end
end
CALL closeport(handlername)
EXIT
readOPT:
lister set ALH busy 1
httpargs = sethttparg(DDir)
CALL gogetrm(namestr)
lister set ALH busy 0
if exists(DDir||refyl) then do
dopus read DDir||refyl
if event='dropfrom' then CALL showdownloads()
end
else
CALL givemsg(refyl||'" not downloaded!"')
RETURN
dereselect: procedure expose ALH reselfile.
arg oldsel
lister query ALH numselfiles
totsel = result
if totsel > 0 then do
lister query ALH selfiles stem reselfile.
'command none'
end
else do
do i = 0 to oldsel -1
lister select ALH reselfile.i on
end
end
lister refresh ALH full
RETURN totsel
preselect: procedure expose ALH prefile
lister query ALH numselfiles
totsel = result
if totsel > 0 then do
lister query ALH selfiles var preselfiles
CALL open('w',prefile,'w')
CALL writeln('w',preselfiles)
CALL close('w')
'command none'
lister set ALH busy 0
lister refresh ALH full
end
else CALL chkpresel()
RETURN
chkpresel: procedure expose ALH prefile
if exists(prefile) then do
CALL open('r',prefile,'r')
preselfiles = readln('r')
CALL close('r')
wrdcnt = words(preselfiles)
if wrdcnt > 0 then do
do i = 1 to wrdcnt
lister select ALH word(preselfiles,i) on
end
lister refresh ALH full
lister query ALH numselfiles
totsel = result
if totsel > 0 then do
CALL givemsg(totsel||'" Re-selected"')
if totsel = wrdcnt then ADDRESS command 'delete >NIL:' prefile
end
end
end
RETURN
downloadOPT:
lister set ALH source
lister set ALH busy 1
httpargs = sethttparg(DDir)
gotem = gogetem()
lister set ALH busy 0
if gotem then CALL showdownloads()
RETURN
chngURL:
tick = tick +1
if tick = amiURL.0 +1 then tick = 1
newurl = amiURL.tick
if index(upper(amiURL.tick),"HTTP://") = 1 then newurl = right(amiURL.tick,length(amiURL.tick) -7)
RETURN newurl
load:
parse arg pthfyl
listingOK = chkfyl(pthfyl) /* Returns with file still open. */
if ~listingOK then do
CALL close('r')
CALL givemsg(pthfyl||LF||'"Doesn''t contain an aminet listing."')
end
else do
lister set ALH source
ln = chkln
lister set ALH title toploading
lister refresh ALH full
lister set ALH busy 1
lister clear ALH
CALL loadlist() /* File gets closed here. */
topmsg = gettopmsg(pthfyl)
lister set ALH busy 0
lister set ALH title topmsg
lister refresh ALH full
end
RETURN
chkrunning:
ALH = 0
lister query all var handles
hcount = words(handles)
do h = 1 to hcount
hndl = word(handles,h)
lister query hndl toolbar /* query label doesn't want to work?! */
TB = upper(result)
if index(TB,HTTPToolBar) > 0 then do
ALH = hndl
leave
end
end
RETURN ALH
loadrunning:
arg ALH
lister set ALH source
lister set ALH title toploading
lister set ALH busy 1
lister refresh ALH full
lister clear ALH
CALL loadlist() /* File gets closed here. */
topmsg = gettopmsg(listingfyl)
lister set ALH busy 0
lister set ALH title topmsg
lister refresh ALH full
RETURN
loadlist:
lynnum = 0
MDF = 0; HRP = 0
Amotd = ""
LF = '0a'x
do while ~EOF('r')
if ln ~= "" then do
if index(ln,"|") = 1 then do
MDF = 0; HRP = 0
do while index(ln,"|") = 1 & ~EOF('r')
select
when index(ln,"most downloaded files") > 0 then MDF = 1
when index(ln,"highest rated programs") > 0 then HRP = 1
otherwise NOP
end
ln = readln('r')
end
parse var ln +18 t1 +1 ap +10 t2 +1 .
if ~((t1||t2 == " ") & (index(ap,"/") >0)) & (MDF | HRP) then do
MDF = 0; HRP = 0
end
end
if EOF('r') then LEAVE
parse var ln +18 t1 +1 ap +10 t2 +1 .
if index(ln,"Message of the day:") > 0 then do
do while ~EOF('r') & ~((t1||t2 == " ") & (index(ap,"/") >0))
Amotd = Amotd||ln||LF
ln = readln('r')
parse var ln +18 t1 +1 ap +10 t2 +1 .
end
end
if EOF('r') then LEAVE
parse var ln aminame amidir amirest
if (index(FilterOut,amidir) = 0) & (t1||t2 == " ") & (index(ap,"/") >0) then do
lynnum = lynnum +1
select
when MDF then linedayt = lynnum +320025661
when HRP then linedayt = lynnum +638755261
otherwise linedayt = lynnum
end
entry.name = aminame
entry.comment = amidir||amirest
entry.date = linedayt
lister addstem ALH entry
end
end
ln = readln('r')
end
CALL close('r')
RETURN
gogetem:
lister query ALH numselfiles
totsel = result
gotsome = 0
numdwnldd = 0
if totsel ~> 0 then RETURN gotsome
lister query ALH selfiles stem fyl.
loadmsg = loadHTTPresume()
if loadmsg = "" then do
ADDRESS 'DOPUS.1'
do i = 0 to totsel -1
lister query ALH entry fyl.i stem fylinfo
parse var fylinfo.comment amipath rest
if totsel > 1 then
DLfsz.i = getasz(left(amipath||rest,16))
Uset.i = amiURL||amipath||"/"||fyl.i
end
tmp = time(reset) /* set elapsed time to 0.00 */
if totsel > 1 then do /* Bubble smallest to highest */
do ii=0 to totsel -1
do j=ii+1 to totsel -1
if DLfsz.ii > DLfsz.j then parse value Uset.ii Uset.j fyl.ii fyl.j DLfsz.ii DLfsz.j with Uset.j Uset.ii fyl.j fyl.ii DLfsz.j DLfsz.ii .
end
end
end
ADDRESS(Port)
do J=0 to totsel-1
SET OUTFILE DDir||fyl.J
SET URL Uset.J
START
Working=1
do while Working>0
QUERY FINISHED
Working=Result
CALL Delay(150) /* Pause 3 seconds */
end
if exists(DDir||fyl.J) then do
numdwnldd = numdwnldd +1
CALL deselect(fyl.J)
ADDRESS(Port)
end
end
QUIT
if (time(elapsed) >soundafter) & exists(soundplayer) & exists(fini_sound) then do
ADDRESS command soundplayer||" >nil: "||fini_sound
CALL delay(100)
end
else
CALL delay(150)
ADDRESS 'DOPUS.1'
lister query ALH numselfiles
numnotfound = result
if numnotfound > 0 then CALL givemsg('"Number of files not downloaded: "'||numnotfound)
end
else
CALL givemsg(loadmsg)
if numdwnldd > 0 then gotsome = 1
RETURN gotsome
gogetrm:
parse arg rf
parse var rf nm "." .
refyl = nm||".readme"
loadmsg = loadHTTPresume()
if loadmsg = "" then do
lister query ALH entry rf stem fylinfo
parse var fylinfo.comment amipath .
Uset = amiURL||amipath||"/"||refyl
ADDRESS(Port)
SET OUTFILE DDir||refyl
SET URL Uset
START
Working=1
do while Working>0
QUERY FINISHED
Working=Result
CALL Delay(150) /* Pause 3 seconds */
end
QUIT
end
else
CALL givemsg(loadmsg)
RETURN
downloadrcnt:
dlsucc = 0
Uset = amiURL||"RECENT"
loadmsg = loadHTTPresume()
if loadmsg = "" then do
ADDRESS(Port)
SET OUTFILE "RAM:RECENT"
SET URL Uset
START
Working=1
do while Working>0
QUERY FINISHED
Working=Result
CALL Delay(150) /* Pause 3 seconds */
end
QUIT
if exists("RAM:RECENT") then dlsucc = 1
end
else
CALL givemsg(loadmsg)
RETURN dlsucc
loadHTTPresume:
succ = ""
TmpFile='T:HTTPResume.tmp.'||random(,,time('s'))||'.'random(,,)
ADDRESS COMMAND 'Run '||HTTPresume||httpargs||TmpFile
CALL Delay(150) /* Wait 3 seconds for HTTPResume to start */
if ~OPEN(PortFile, TmpFile, 'R') then
succ = '"Download failed! Possibly not online?"'
else do
Port=READLN(PortFile)
CLOSE(PortFile)
CALL DELETE(TmpFile)
IF Port='***' then succ = '"HTTPResume couldn''t open its ARexx port!"'
end
RETURN succ
deselect: procedure expose ALH
parse arg fyl
ADDRESS 'DOPUS.1'
lister select ALH fyl off /* De-select that file. */
lister refresh ALH
RETURN
showdownloads:
lister query all
alltrs = result
stillopen = index(alltrs,Dhandle)
select
when stillopen > 0 then do
lister set Dhandle dest
lister read Dhandle DDir
end
when stillopen = 0 then do
lister new "1/200/350/200 " DDir
Dhandle = result
lister wait Dhandle
lister set Dhandle dest
end
otherwise NOP
end
RETURN
slcd:
rcnt = ""
lister query source; if RC > 0 then RETURN rcnt
src = result
lister query src numselfiles
totsel = result
if (totsel = 0) | (totsel > 1) then RETURN rcnt
lister query src path
srcpth = result
lister query src selfiles stem fyl.
amilist = fyl.0
rcnt = srcpth||amilist
lister select src amilist off /* De-select that file. */
lister refresh src
RETURN rcnt
chkfyl: procedure expose chkln recdayt
parse arg amilisting
rcntOK = 1
lncntr = 0
maxcnt = 100
recdayt = ""
if ~open('r',amilisting,'r') then CALL tata('"Can''t open "'||amilisting, 20)
chkln = readln('r')
parse var chkln +18 t1 +1 ap +10 t2 +1 .
do while ~EOF('r') & ~((t1||t2 == " ") & (index(ap,"/") >0)) & ~(lncntr > maxcnt)
lncntr = lncntr +1
chkln = readln('r')
if index(chkln,"Date:") = 1 then recdayt = getrecdayt(chkln)
parse var chkln +18 t1 +1 ap +10 t2 +1 .
end
if EOF('r') | (lncntr > maxcnt) then do
CALL close('r')
rcntOK = 0
end
RETURN rcntOK
getrecdayt:
parse arg rdl
rcd = ""
parse var rdl "Date:" . ", " dayt +11 rest
if index("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",word(dayt,2)) > 0 then rcd = dayt
RETURN rcd
findstring: procedure expose ALH srchstr
oldstr = ""
if (srchstr ~= "SRCHSTR") & (srchstr ~= "RESULT") then oldstr = srchstr
dopus getstring '"Non-case sensitive search. Don''t use wild cards." "'||oldstr||'" Okay|Cancel'
srchstr = result
butt = DOPUSRC
Usrchstr = upper(srchstr)
if (srchstr="RESULT" & butt<1) | (butt=1 & srchstr="RESULT" ) then RETURN
lister query ALH files stem filename.
lister query ALH numfiles
filecount = result
lister clear ALH abort
lister set ALH newprogress abort bar name title
lister set ALH newprogress title "Searching both columns for "||srchstr
lister set ALH newprogress bar numsel 0
do i = 0 to filecount-1
lister set ALH newprogress name filename.i
lister set ALH newprogress bar filecount i
lister query ALH entry filename.i stem fileinfo.
if index(upper(filename.i||fileinfo.comment),Usrchstr) > 0 then lister select ALH filename.i 1
lister query ALH abort
if result = 1 then do
lister set ALH newprogress off
lister refresh ALH full
RETURN
end
end
lister set ALH newprogress off
lister refresh ALH full
RETURN
gettopmsg:
parse arg lstfyl
tfnm = fylname(lstfyl)
if datatype(tfnm,'n') then
topdefault = topdefault||" "||recdayt
else
topdefault = tfnm||" "||recdayt
RETURN topdefault
fylname:
parse arg fdir
slpos = lastpos('/',fdir)
parse var fdir ":"fn
if slpos > 0 then fn = substr(fdir,slpos+1)
RETURN fn
getasz: procedure
arg afsz
fsz = 0
parse var afsz nm sz .
kpos = index(sz,'K')
mpos = index(sz,'M')
select
when kpos > 0 then fsz=left(sz,kpos-1)
when mpos > 0 then fsz=left(sz,mpos-1)*1000
otherwise NOP
end
RETURN fsz
readAmotd:
if length(Amotd) < maxsgsz then
CALL givemsg('"'||Amotd||'"')
else
CALL readmsg(Amotd)
RETURN
sethttparg:
parse arg dwldir
if PRXY = "PRXY" | PRXY = "" then
hargs = ' OVERWRITE SD='||dwldir||' DEBUG='||dwldir||'HTTPdebug.log WINWIDTH=450 GUI NOERRREQ RXPORTFILE='
else
hargs = ' OVERWRITE PROXY='||PRXY||' SD='||dwldir||' DEBUG='||dwldir||'HTTPdebug.log WINWIDTH=450 GUI NOERRREQ RXPORTFILE='
RETURN hargs
readmsg: procedure
parse arg msg
CALL open('w',"T:temp_msg",'w')
CALL writeln('w',msg)
CALL close('w')
dopus read "T:temp_msg"
RETURN
timedmsg:
ADDRESS 'DOPUS.1'
parse arg msg, dt
lister set ALH title msg
lister refresh ALH full
CALL delay(dt)
lister set ALH title topmsg
lister refresh ALH full
RETURN
givemsg:
ADDRESS 'DOPUS.1'
parse arg msg
dopus request ''msg' OK'
RETURN
tata:
ADDRESS 'DOPUS.1'
parse arg msg
dopus request ''msg' OK'
EXIT
syntax:
LF = '0a'x
ADDRESS 'DOPUS.1'
errmsg = '"ABORTING!"'||LF||'"Please report this error:"'||LF||'"Syntax Error "'||rc||'" , "'||"'"||errortext(rc)||"'"||'" in line "'||sigl||'"."'
lister set ALH busy 0
dopus request ''errmsg' OK'
lister query ALH handler
if result = handlername then CALL closeport(handlername)
lister close ALH
EXIT